import axios from 'axios'
import { Message } from 'element-plus'


const instance = axios.create({
  baseURL: import.meta.env.VITE_APP_URL,
  timeout: 60000,
  headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
})
const request = ({ url, method = 'GET', params = {} }) => {
  return new Promise((resolve, reject) => {
    const requestBody = method.toLowerCase() !== 'get' ? 'data' : 'params'
    const result = instance({ url, method, [requestBody]: params });
    result.then(value => resolve(value), reason => Message.error(JSON.stringify(reason)));
  });
};

export const GOODSLIST = async params => await request({url: '/goods', params})